package com.lanxiao.cloud.modules.file.application.assembler;

import com.lanxiao.cloud.modules.file.application.dto.FileConfigureCmdUpdate;
import com.lanxiao.cloud.modules.file.application.dto.FileConfigureDto;
import com.lanxiao.cloud.modules.file.domain.model.FileConfigure;
import com.lanxiao.cloud.user.api.fill.BaseDtoFillHandleFactory;
import java.util.List;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import org.springframework.stereotype.Component;

/**
 * @author ：qiaoliang
 * @date ：2021-10-25
 */
@Component
public class FileConfigureAssembler {

  private final BaseDtoFillHandleFactory<Long> fillHandleFactory;

  public FileConfigureAssembler(
      BaseDtoFillHandleFactory<Long> fillHandleFactory) {
    this.fillHandleFactory = fillHandleFactory;
  }

  public FileConfigure toFileConfigure(Long id, FileConfigureCmdUpdate update) {
    FileConfigure fileConfigure = FileConfigureConverter.INSTANCE.toFileConfigure(update);
    fileConfigure.setId(id);
    return fileConfigure;
  }

  public List<FileConfigureDto> toFileConfigureDto(List<FileConfigure> fileConfigure){
    final List<FileConfigureDto> fileConfigureDtos = FileConfigureConverter.INSTANCE.toFileConfigureDto(
        fileConfigure);
    fillHandleFactory.fillHandle(fileConfigureDtos);
    return fileConfigureDtos;
  }

  @Mapper
  public interface FileConfigureConverter {

    FileConfigureConverter INSTANCE = Mappers.getMapper(FileConfigureConverter.class);

    FileConfigure toFileConfigure(FileConfigureCmdUpdate update);

    FileConfigureDto toFileConfigureDto(FileConfigure fileConfigure);
    List<FileConfigureDto> toFileConfigureDto(List<FileConfigure> fileConfigure);

  }

}
